<template>
	<view style="padding-bottom: 50upx;">
		<u-sticky :h5-nav-height="0" bg-color="#F5F5F5" offset-top="0">
			<u-tabs :list="tabList" :is-scroll="false" :current="current" @change="change"></u-tabs>

			<view class="orderInfoNum flex align-center justify-center">
				<view class="orderInfoNum-box">
					<view class="orderInfoNum-box-title">
						今日接单情况
					</view>
					<view class="orderInfoNum-box-num flex align-center justify-between">
						<view class="orderInfoNum-box-num-item">
							<view class="orderInfoNum-box-num-item-top">
								{{indent.indentCount?indent.indentCount:0}}
								<text>单</text>
							</view>
							<view class="orderInfoNum-box-num-item-txt">
								成单量
							</view>
						</view>
						<view class="orderInfoNum-box-num-item">
							<view class="orderInfoNum-box-num-item-top">
								{{riderLine?riderLine:0}}
								<text>小时</text>
							</view>
							<view class="orderInfoNum-box-num-item-txt">
								听单时长
							</view>
						</view>
						<view class="orderInfoNum-box-num-item">
							<view class="orderInfoNum-box-num-item-top">
								{{indent.indentMoney?indent.indentMoney:0}}
								<text>元</text>
							</view>
							<view class="orderInfoNum-box-num-item-txt">
								今日收入
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="boxa" @click="goOrder(item)" v-for="(item,index) in list" :key="index">
			<view class="flex align-center justify-between padding-lr">
				<view class="flex align-center">
					<image src="../../static/image/data.png" style="width: 34rpx;height: 38rpx;"></image>
					<!-- <view class="margin-left-sm">预约订单</view> -->
					<view class="margin-left-sm" v-if="item.indentType==1"> 即时代驾</view>
					<view class="margin-left-sm" v-if="item.indentType==2">朋友代叫</view>
					<view class="margin-left-sm" v-if="item.indentType==3">预约代驾</view>
				</view>
				<view v-if="item.indentType==3&&item.hopeTime">预约时间：{{item.hopeTime}}</view>
			</view>
			<view class="margin-tb-sm" style="width: 100%;height:1rpx;background: #F2F2F2;"></view>
			<view class="addbox bgs margin-lr margin-bottom">
				<view class="add_cont">
					<view class="green"></view>
					<view class="add_tit">
						<view>{{item.shipAddress}}</view>
					</view>
				</view>
			</view>
			<view class="addbox bg margin-lr">
				<view class="add_cont">
					<view class="orgin"></view>
					<view class="add_tit">{{item.deliveryAddress?item.deliveryAddress:'用户未选择目的地'}}</view>
				</view>
			</view>
			<view class="margin-lr margin-top-sm" v-if="item.remarks">备注：{{item.remarks}}</view>
			<view class="margin-tb-sm" style="width: 100%;height:1rpx;background: #F2F2F2;"></view>
			<view class="flex align-center justify-between padding-lr ">
				<view class="flex align-center" v-if="item.riderDistance>=1000">
					<image src="../../static/image/add.png" style="width: 30rpx;height: 35rpx;"></image>
					<view class="margin-left-xs">距您<text
							style="color: #3699FF;">{{(Number(item.riderDistance) / 1000).toFixed(2)}}km</text></view>
				</view>
				<view class="flex align-center" v-else>
					<image src="../../static/image/add.png" style="width: 30rpx;height: 35rpx;"></image>
					<view class="margin-left-xs">距您<text
							style="color: #3699FF;">{{Number(item.riderDistance).toFixed(2)}}m</text></view>
				</view>
				<view class="flex align-center">预估
					<view style="color: #FF2020;font-size: 32rpx;">
						<text>¥</text><text class="text-bold" style="font-size: 38rpx;">{{item.riderMoney}}</text>
					</view>
				</view>
			</view>
			<view class="btn" @click.stop="jiedan(item.indentNumber)">抢单</view>
		</view>
		<empty v-if="list.length==0"></empty>



		<!-- 底部接单按钮 -->
		<!-- <view class="bottomBtn">
			<image v-if="isShowMap == false" @click="showMaps()" class="bottomBtn-img"
				src="../../static/image/startOrder.png" mode=""></image>
			<image v-else @click="showOrders()" class="bottomBtn-img" src="../../static/image/endOrder.png" mode="">
			</image>
		</view> -->
		<u-popup :show="isShowTipImgs" zIndex="99999999" mode="top">
			<view class="tipsmkf">
				申请麦克风权限，便于您使用该功能上传您的语音，
			</view>
		</u-popup>
	</view>
</template>

<script>
	// #ifdef H5
	var recorder; // 定义一个MediaRecorder对象
	var stream; //定义一个音频流的对象
	var chunks = []; // 定义一个用于存储音频数据片段的数组
	// #endif
	import configdata from '@/common/config.js';
	import empty from '@/components/empty'
	export default {
		components: {
			empty
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: this.tuiguang,
				path: '/pages/index/index',
				imageUrl: this.tuiguangImg,
			}
		},
		data() {
			return {
				//录音相关参数
				// #ifndef H5
				//H5不能录音
				RECORDER: uni.getRecorderManager(),
				// #endif
				isShowTipImgs: false,
				//播放语音相关参数
				AUDIO: uni.createInnerAudioContext(),
				playMsgid: null,
				VoiceTimer: null,
				contentUrl: '',
				recordLength: '',
				voicePaths: '',
				voicePath: '',
				blobData: '',
				recordTimer: null,

				tuiguang: '',
				tuiguangImg: '',
				time: '',
				indent: {},
				latitude: '',
				longitude: '',
				province: '',
				city: '',
				district: '',
				list: [],
				page: 1,
				checkCertification: 0, //是否实名 0审核 1已实名 2已拒绝
				cashDeposit: 0, //缴纳保证金
				onLineFlag: 1, //1上线 2下线
				arr: [],
				showModal1: true,
				riderLine: 0,
				tabList: [/* {
						name: '即时代驾',
						id: 1
					},
					// {
					// 	name: '包时代驾',
					// 	id: 1
					// },
					{
						name: '朋友代叫',
						id: 2
					},
					{
						name: '预约代驾',
						id: 3
					} */
				],
				current: 0,
				isVip: -1

			}
		},
		onHide() {
			console.log('离开卸载')
			this.voiceEnd()
			this.AUDIO.stop();
		},
		onLoad() {
			let that = this
			// 是否开启包时代驾	426
			that.$Request.getT('/app/common/type/426').then(res => {
				if (res.code == 0) {
					if (res.data && res.data.value && res.data.value == '是') {
						let list = {
							id: 1,
							name: '包时代驾'
						}
						that.tabList.push(list)
					}
				}
			});
			// #ifndef H5
			//录音开始事件
			that.RECORDER.onStart((e) => {
				console.log('监听开始录音' + e)
			})
			//录音结束事件
			that.RECORDER.onStop((e) => {
				console.log('监听结束录音' + e)
				that.recordEnd(e);
			})
			// #endif
			let sysInfo = uni.getSystemInfoSync()
			let tabbarHeight = sysInfo.screenHeight - sysInfo.safeArea.bottom
			console.log(tabbarHeight, '2222222')
			that.userId = uni.getStorageSync('userId')
			if (that.userId) {

				that.$Request.getT('/app/indent/getRiderIndentList?page=1&limit=2&indentState=2').then(
					res => {
						if (res.code === 0) {
							if (res.data.records && res.data.records.length != 0) {
								that.StartMp()
							} else {
								uni.removeStorageSync('orderIndentId')
							}
						}
					});

				that.shouru()
				that.getNewOrder()
				uni.getLocation({
					// #ifdef APP
					type: 'wgs84',
					// #endif
					// #ifndef APP
					type: 'gcj02', //wgs84  gcj02
					// #endif
					success: function(res) {
						console.log(res, '获取经纬度')
						that.latitude = res.latitude
						that.longitude = res.longitude
						uni.setStorageSync('latitude', res.latitude)
						uni.setStorageSync('longitude', res.longitude)
						let data = {
							lat: res.latitude,
							lng: res.longitude
						}
						that.$Request.getT('/app/Login/selectCity', data).then(res => {
							if (res.code === 0) {
								that.province = res.data.province
								that.city = res.data.city
								that.district = res.data.district
								that.getLocation()
							}
						});
						that.taskData();

					},
					fail: function(ree) {
						console.log(ree, '获取地址失败')
						if (uni.getStorageSync('latitude') && uni.getStorageSync('longitude')) {
							that.latitude = uni.getStorageSync('latitude')
							that.longitude = uni.getStorageSync('longitude')
							that.taskData();
							that.getLocation()
						} else {
							uni.startLocationUpdate({
								type: 'gcj02', //gcj02  wgs84
								isHighAccuracy: true, //开启高精度定位(！！！必需)
								geocode: true,
								success: res => {
									uni.onLocationChange(function(res2) {
										console.log('实时纬度：' + res2.latitude);
										console.log('实时经度：' + res2.longitude);
										that.latitude = res2.latitude
										that.longitude = res2.longitude
										uni.setStorageSync('latitude', that.latitude)
										uni.setStorageSync('longitude', that.longitude)
										let data = {
											lat: res.latitude,
											lng: res.longitude
										}
										that.$Request.getT('/app/Login/selectCity', data)
											.then(
												res => {
													if (res.code === 0) {
														that.province = res.data.province
														that.city = res.data.city
														that.district = res.data.district
														that.getLocation()
													}
												});
										that.taskData();

									});
								},
								fail: err => {
									// clearInterval(this.ordertimer)
									console.error('开启小程序接收位置消息失败：', err)
								},
								complete: msg => {
									// clearInterval(this.ordertimer)
									console.log('调用开启小程序接收位置消息 API 完成')
								}
							});
						}
					}
				});
				that.time = setInterval(function() {
					that.getNewOrder()
					uni.getLocation({
						// #ifdef APP
						type: 'wgs84',
						// #endif
						// #ifndef APP
						type: 'gcj02', //wgs84  gcj02
						// #endif
						success: function(res) {
							console.log(res, '获取经纬度')
							that.latitude = res.latitude
							that.longitude = res.longitude
							uni.setStorageSync('latitude', res.latitude)
							uni.setStorageSync('longitude', res.longitude)
							let data = {
								lat: res.latitude,
								lng: res.longitude
							}
							that.$Request.getT('/app/Login/selectCity', data).then(res => {
								if (res.code === 0) {
									that.province = res.data.province
									that.city = res.data.city
									that.district = res.data.district
									that.getLocation()
								}
							});
							that.taskData();

						},
						fail: function() {
							console.log('获取地址失败')
							if (uni.getStorageSync('latitude') && uni.getStorageSync('longitude')) {
								that.latitude = uni.getStorageSync('latitude')
								that.longitude = uni.getStorageSync('longitude')
								that.taskData();
								that.getLocation()
							} else {
								that.taskData();
								that.getLocation()
								uni.startLocationUpdate({
									// #ifdef APP
									type: 'wgs84',
									// #endif
									// #ifndef APP
									type: 'gcj02', //wgs84  gcj02
									// #endif
									isHighAccuracy: true, //开启高精度定位(！！！必需)
									geocode: true,
									success: res => {
										uni.onLocationChange(function(res2) {
											console.log('实时纬度：' + res2.latitude);
											console.log('实时经度：' + res2.longitude);
											that.latitude = res2.latitude
											that.longitude = res2.longitude
											uni.setStorageSync('latitude', that
												.latitude)
											uni.setStorageSync('longitude', that
												.longitude)
											let data = {
												lat: res.latitude,
												lng: res.longitude
											}
											that.$Request.getT(
												'/app/Login/selectCity',
												data).then(res => {
												if (res.code === 0) {
													that.province = res
														.data
														.province
													that.city = res.data
														.city
													that.district = res
														.data
														.district
													that.getLocation()
												}
											});
											that.taskData();

										});
									},
									fail: err => {
										// clearInterval(this.ordertimer)
										console.error('开启小程序接收位置消息失败：', err)
									},
									complete: msg => {
										// clearInterval(this.ordertimer)
										console.log('调用开启小程序接收位置消息 API 完成')
									}
								});
							}
						}
					});
				}, 5000)

			}
		},
		onShow() {
			this.$Request.getT('/app/common/type/358').then(res => {
				if (res.code === 0) {
					uni.setStorageSync('tuiguang', res.data.value)
					this.tuiguang = res.data.value;
				}
			});
			this.$Request.getT('/app/common/type/357').then(res => {
				if (res.code === 0) {
					uni.setStorageSync('tuiguangImg', res.data.value)
					this.tuiguangImg = res.data.value;
				}
			});
			let that = this

			that.$Request.getT('/app/common/type/268').then(res => { //师傅端订单状态通知 268
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.arr.push(res.data.value)
					}
				}
			})
			that.$Request.getT('/app/common/type/338').then(res => { //师傅新订单通知 338
				if (res.code == 0) {
					if (res.data && res.data.value) {
						that.arr.push(res.data.value)
					}
				}
			})
			that.userId = uni.getStorageSync('userId')
			if (that.userId) {
				that.getVip()
				that.getUserInfo()
				that.taskData();
				that.shouru()
				if (that.showModal1) {
					// #ifdef MP-WEIXIN
					that.openMsg()
					// #endif
				}
			} else {
				clearInterval(that.time)
				this.indent = {}
			}

		},
		methods: {
			// 获取会员详情
			getVip() {
				this.$Request.getT("/app/UserVip/selectUserVip").then(res => {
					if (res.code == 0 && res.data) {
						this.isVip = res.data.isVip
					}
				});
			},
			StartMp() { //  开始录音
				let that = this
				// #ifdef APP
				// 在弹出选择弹框之前先判断一下是否获取了相册权限
				const sysInfo = uni.getSystemInfoSync()
				if (sysInfo.osName == 'ios') { //ios

				} else { //安卓
					var Manifest = plus.android.importClass("android.Manifest");
					var MainActivity = plus.android.runtimeMainActivity();
					let flag = MainActivity.checkSelfPermission(Manifest.permission.RECORD_AUDIO)
					console.log(flag); // 查看是否拥有相机权限 -1/0
					if (flag == -1) { //没有授权
						that.isShowTipImgs = true
						plus.android.requestPermissions(['android.permission.RECORD_AUDIO'], (success) => {
							that.isShowTipImgs = false
						}, (err) => {
							that.isShowTipImgs = false
						})
						return
					} else {
						that.isShowTipImgs = false
					}

				}
				// #endif
				// #ifdef H5
				if (stream) {
					stream.getTracks().forEach((track) => track.stop())
					stream = null
				}
				if (recorder) {
					recorder = null
				}
				that.recordLength = 0
				that.voicePaths = '';
				that.voicePath = '';
				that.startRecord()
				// #endif
				// #ifndef H5
				that.RECORDER.start({
					format: "mp3"
				}); //录音开始,
				that.recordBegin()
				// #endif
			},
			//开始录音
			startRecord: async function() {
				let _this = this
				// 获取麦克风音频数据流
				stream = await navigator.mediaDevices.getUserMedia({
					audio: true
				})
				// 初始化MediaRecorder对象
				recorder = new MediaRecorder(stream);
				// console.log('asdsad___' + recorder)
				// alert('asdsad___' + recorder)
				// 将 stream 转成 blob 来存放
				recorder.ondataavailable = (blobEvent) => {
					chunks.push(blobEvent.data);
				}
				// 停止时生成预览的 blob url
				recorder.onstop = () => {
					const blob = new Blob(chunks, {
						type: 'audio/mp3'
					})
					_this.voicePaths = blob;
					_this.blobData = blob;

				}
				recorder.start();
				_this.recordBegin()
			},
			//录音开始UI效果
			recordBegin() {
				this.recordLength = 0;
				this.recordTimer = setInterval(() => {
					this.recordLength++;
				}, 1000)
			},
			// 结束录音
			voiceEnd() {
				//原生录音停止
				// #ifdef H5
				//停止录音
				if (recorder.state != "inactive") {
					recorder.stop();
				}
				//把音频流也停止掉
				stream.getTracks().forEach((track) => track.stop())
				this.uplodMp3(this.voicePaths);
				// #endif

				// #ifndef H5
				this.RECORDER.stop(); //录音结束
				// #endif

			},
			//录音结束(回调文件)
			recordEnd(e) {
				clearInterval(this.recordTimer);
				// uni.showLoading({
				// 	title: '发送中'
				// });
				let indentId = uni.getStorageSync('orderIndentId')
				console.log('9999999999999' + indentId)
				console.log(this.recordLength, e.tempFilePath && indentId && this.recordLength > 3)
				if (indentId && e.tempFilePath && this.recordLength > 3) {
					uni.uploadFile({ // 上传接口
						url: this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + indentId, //真实的接口地址
						filePath: e.tempFilePath,
						name: 'file',
						success: (uploadFileRes) => {
							console.log('------------' + uploadFileRes.data)
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {
								console.log('上传成功')
							} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}

						},
						fail: (err) => {
							console.log('err' + err)
						}
					});
				}
			},
			//上传mp3格式的音频
			uplodMp3(recordPath) {
				let _this = this;
				clearInterval(_this.recordTimer);
				let indentId = uni.getStorageSync('orderIndentId')

				if (indentId && _this.blobData && _this.recordLength > 3) {
					uni.uploadFile({ // 上传接口
						url: _this.config("APIHOST1") + '/app/indent/uploadIndent?indentId=' + indentId, //真实的接口地址
						file: _this.blobData,
						name: 'file',
						success: (uploadFileRes) => {
							uni.hideLoading();
							let url = JSON.parse(uploadFileRes.data)
							if (url.code == 0) {} else {
								uni.showToast({
									title: url.msg,
									icon: 'none'
								})
							}
						}
					});
				}
			},
			config: function(name) {
				var info = null;
				if (name) {
					var name2 = name.split("."); //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null;
					} else {
						info = configdata[name] || null;
					}
					if (info == null) {
						let web_config = cache.get("web_config");
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null;
							} else {
								info = web_config[name] || null;
							}
						}
					}
				}
				return info;
			},

			change(index) {
				if (uni.getStorageSync('token')) {
					this.current = index
					this.taskData()
				}
			},
			// 今日收入、订单量
			shouru() {
				this.$Request.getT('/app/userinfo/findIncome').then(res => {
					if (res.code == 0) {
						this.indent = res.data
					}
					console.log('res', res)

				});
			},
			getNewOrder() {

				this.$Request.getT('/app/message/getOrderMessage').then(res => {
					if (res.code == 0) {
						if (res.data > 0) {
							console.log('11111111')
							this.aplayAudio()
						}
					}
				});
			},
			//接单池刷新
			aplayAudio() {
				// console.log('语音提示')
				const innerAudioContext = uni.createInnerAudioContext();
				innerAudioContext.autoplay = true;
				// innerAudioContext.src ='../../static/mpc/order.mp3';
				// innerAudioContext.src =
				// 	'https://pw.xianmxkj.com/file/uploadPath/2022/01/19/0753211f78d718d44ee6372e33eae9ee.mp3';
				innerAudioContext.src =
										'https://pw.xianmxkj.com/file/uploadPath/2022/03/15/c096db4257ecc2547814d4f51c6518bd.mp3';
				innerAudioContext.onPlay(() => {
					console.log('开始播放');
				});
				innerAudioContext.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});
			},
			// 获取个人信息
			getUserInfo() {
				this.$Request.getT("/app/userinfo/findUserInfoById").then(res => {
					if (res.code == 0) {
						this.$nextTick(function() {
							this.checkCertification = res.data.checkCertification
							this.cashDeposit = res.data.cashDeposit
							this.onLineFlag = res.data.onLineFlag
							this.riderLine = res.data.riderLine
						})
					} else {
						this.$queue.logout();
						uni.showModal({
							showCancel: false,
							title: '登录失败',
							content: res.msg,
						});
					}
				});
			},
			goOrder(e) {
				if (this.userId) {
					if (this.checkCertification == 1) {
						this.$Request.getT('/app/common/type/261').then(res => {
							if (res.code === 0) {
								let baozhengjin = res.data.value;
								let DepositSwitch = uni.getStorageSync('DepositSwitch')
								if (DepositSwitch == '是') {
									if ((Number(this.cashDeposit) < Number(baozhengjin))) {
										uni.showModal({
											title: '提示',
											content: '保证金不足，请先缴纳保证金后再接单',
											success: function(res) {
												if (res.confirm) {
													console.log('用户点击确定');
													uni.navigateTo({
														url: '/my/wallet/baozhengjin'
													})
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return
									}
								}
								let VipSwitch = uni.getStorageSync('VipSwitch')
								if (VipSwitch == '是') {
									if (this.isVip != 1) {
										uni.showModal({
											title: '提示',
											content: '接单需要先开通会员',
											success: function(res) {
												if (res.confirm) {
													console.log('用户点击确定');
													uni.navigateTo({
														url: '/my/vip/vip'
													})
												} else if (res.cancel) {
													console.log('用户点击取消');
												}
											}
										});
										return
									}
								}

								uni.navigateTo({
									url: '/pages/index/orderDet?indentNumber=' + e.indentNumber
								})
							}
						});

					} else if (this.checkCertification == 0) {
						uni.showToast({
							title: '实名认证审核中，请稍等...',
							icon: 'none'
						})
						return
					} else if (this.checkCertification == '' || this.checkCertification == null) {
						uni.showModal({
							title: '提示',
							content: '请先实名认证后再接单',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
									uni.navigateTo({
										url: '/my/renzheng/index'
									})
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return;
					}
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
			// 获取新任务数据
			taskData() {
				let data = {
					page: this.page,
					limit: 10,
					od: this.latitude,
					ol: this.longitude,
					receivingPettern: 2,
					/* indentType: this.tabList[this.current].id, */
				}
				if (this.current == 0) { //即时代驾
					data.moneyType = 2
				} else if (this.current == 1) {
					data.moneyType = 1
				}
				this.$Request.getT('/app/indent/findNewIndent', data).then(res => {
					uni.hideLoading()
					if (res.code == 0) {

						this.totalCount = res.data.totalCount
						if (this.page == 1) {
							this.list = res.data.records
						} else {
							this.list = [...this.list, ...res.data.records]
						}
					}
					uni.stopPullDownRefresh();
				});
			},
			// 上传师傅位置
			getLocation() {
				let data = {
					lng: this.longitude,
					lat: this.latitude,
					userId: this.userId,
					province: this.province,
					city: this.city,
					district: this.district,
				}
				this.$Request.getT('/timedtask/riderLocation', data).then(res => {
					if (res.code == 0) {
						console.log('上传师傅位置')
					}
				});
			},

			//接单
			jiedan(indentNumber) {
				// #ifdef MP-WEIXIN
				if (uni.getStorageSync('sendMsg')) {
					uni.requestSubscribeMessage({
						tmplIds: this.arr,
						success(re) {
							// console.log(re,'**********')
							var datas = JSON.stringify(re);
							if (datas.indexOf("accept") != -1) {
								console.log(re)
							}
						},
						fail: (res) => {
							console.log(res)
						}
					})
				}
				// #endif
				if (this.userId) {
					if (this.onLineFlag == 1) {
						if (this.checkCertification == 1) {
							this.$Request.getT('/app/common/type/261').then(res => {
								if (res.code === 0) {
									let baozhengjin = res.data.value;
									let DepositSwitch = uni.getStorageSync('DepositSwitch')
									if (DepositSwitch == '是') {
										if ((Number(this.cashDeposit) < Number(baozhengjin))) {
											uni.showModal({
												title: '提示',
												content: '还未缴纳保证金，请先去缴纳保证金',
												success: function(res) {
													if (res.confirm) {
														console.log('用户点击确定');
														uni.navigateTo({
															url: '/my/wallet/baozhengjin'
														})
													} else if (res.cancel) {
														console.log('用户点击取消');
													}
												}
											});
											return
										}
									}
									let VipSwitch = uni.getStorageSync('VipSwitch')
									if (VipSwitch == '是') {
										if (this.isVip != 1) {
											uni.showModal({
												title: '提示',
												content: '接单需要先开通会员',
												success: function(res) {
													if (res.confirm) {
														console.log('用户点击确定');
														uni.navigateTo({
															url: '/my/vip/vip'
														})
													} else if (res.cancel) {
														console.log('用户点击取消');
													}
												}
											});
											return
										}
									}
									let that = this
									uni.showModal({
										title: '提示',
										content: '确定抢单吗？',
										success: function(res) {
											if (res.confirm) {
												// console.log('用户点击确定');
												that.$Request.postT(
														'/app/indent/indentReceiving?indentNumber=' +
														indentNumber)
													.then(res => {
														if (res.code == 0) {
															that.taskData()
															uni.showToast({
																title: '接单成功',
																icon: 'none'
															})

															setTimeout(function() {
																uni.switchTab({
																	url: '/pages/order/order'
																})
															}, 1000)
														} else {
															that.taskData()
															uni.showToast({
																title: res.msg,
																icon: 'none',
																duration: 1500
															})
														}
													});
											} else if (res.cancel) {
												// console.log('用户点击取消');
											}
										}
									});
								}
							});
						} else if (this.checkCertification == 0) {
							uni.showToast({
								title: '实名认证审核中，请稍等...',
								icon: 'none'
							})
							return
						} else if (this.checkCertification == '' || this.checkCertification == null) {
							uni.showModal({
								title: '提示',
								content: '请先实名认证后再接单',
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
										uni.navigateTo({
											url: '/my/renzheng/index'
										})
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
							return;
						}
					} else {
						let that = this
						uni.showModal({
							title: '提示',
							content: '当前下线中,是否现在上线?',
							complete: function(ret) {
								if (ret.confirm) {
									console.log('用户点击确定');
									uni.showLoading({
										title: '修改中...',
									})
									that.$Request.postT("/app/user/updateLine").then(res => {
										uni.hideLoading();
										if (res.code === 0) {
											that.getUserInfo();
										} else {
											that.$queue.showToast(res.msg)
										}
									});
								} else if (ret.cancel) {
									console.log('用户点击取消');
								}
							}
						});
						return;
					}
				} else {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}

			},

			// 开启订阅消息
			openMsg() {
				console.log('订阅消息')
				var that = this
				uni.getSetting({
					withSubscriptions: true, //是否获取用户订阅消息的订阅状态，默认false不返回
					success(ret) {
						console.log(ret.subscriptionsSetting, '------------------')
						// if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
						if (ret.subscriptionsSetting.itemSettings) {
							uni.setStorageSync('sendMsg', true)
							uni.openSetting({ // 打开设置页 
								success(rea) {
									console.log(rea.authSetting)
								}
							});
						} else { // 用户没有点击“总是保持以上，不再询问”则每次都会调起订阅消息
							console.log(99999)
							uni.setStorageSync('sendMsg', false)
							uni.showModal({
								title: '提示',
								content: '为了更好的体验,请绑定消息推送',
								confirmText: '确定',
								cancelText: '取消',
								success: function(res) {
									if (res.confirm) {
										console.log(that.arr)
										wx.requestSubscribeMessage({
											tmplIds: that.arr,
											success(re) {
												console.log(JSON.stringify(re),
													'++++++++++++++')
												var datas = JSON.stringify(re);
												if (datas.indexOf("accept") != -1) {
													console.log(re)
													// uni.setStorageSync('sendMsg', true)
												}
											},
											fail: (res) => {
												console.log(res)
											}
										})
										// uni.setStorageSync('sendMsg', true)
										console.log('确认')
										that.showModal1 = false
									} else if (res.cancel) {
										console.log('取消')
										// uni.setStorageSync('sendMsg', false)
										that.showModal1 = true
									}
								}
							})
						}
					}
				})
			}
		},
		// 上拉加载
		onReachBottom: function() {
			if (this.userId) {
				if (this.page < this.totalPage) {
					this.page = this.page + 1;
				} else {
					uni.showToast({
						title: '已经最后一页啦',
						icon: 'none'
					})
				}
				this.taskData();
			}

		},
		onPullDownRefresh: function() {
			// #ifdef MP-WEIXIN
			if (uni.getStorageSync('sendMsg')) {
				uni.requestSubscribeMessage({
					tmplIds: this.arr,
					success(re) {
						// console.log(re,'**********')
						var datas = JSON.stringify(re);
						if (datas.indexOf("accept") != -1) {
							console.log(re)
						}
					},
					fail: (res) => {
						console.log(res)
					}
				})
			}
			// #endif
			if (this.userId) {
				this.page = 1;
				this.taskData();

			}

		},
	}
</script>

<style lang="less">
	page {
		background: #F5F5F5;
	}

	.tipsmkf {
		width: 100%;
		padding: 30rpx;
		font-size: 26rpx;
		color: #333333;
		position: fixed;
		top: 50rpx;
		left: 0;
		z-index: 99999 !important;
		background-color: #ffffff;
	}

	/deep/.u-sticky {
		background-color: #F5F5F5;
	}

	.maps {
		width: 100%;
		height: 100vh;
		position: fixed;
		top: 0;
		z-index: 1;
	}

	.bottomBtn {
		position: fixed;
		bottom: 88rpx;
		right: 20rpx;
		z-index: 10;

		.bottomBtn-img {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
		}

	}

	.orderInfoNum {
		width: 100%;
		height: auto;
		background-color: #F5F5F5;
		padding: 30rpx 0;

		.orderInfoNum-box {
			width: 686rpx;
			height: 100%;
			background-color: #FFFFFF;
			border-radius: 24rpx;
			padding: 20rpx;
		}

		.orderInfoNum-box-title {
			width: 100%;
			text-align: center;
			font-weight: bold;
			font-size: 30rpx;
		}

		.orderInfoNum-box-num {
			margin-top: 20rpx;
			text-align: center;
		}

		.orderInfoNum-box-num-item-top {
			font-size: 26rpx;
			font-weight: bold;
		}

		.orderInfoNum-box-num-item-txt {
			color: #999999;
			font-size: 24rpx;
		}
	}

	.boxa {
		background: #FFFFFF;
		border-radius: 24rpx;
		margin: 0 30rpx;
		padding: 30rpx 0;
		margin-bottom: 30rpx;

	}


	.addbox {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 110rpx;
		border-radius: 16rpx;

	}

	.add_cont {
		display: flex;
		align-items: center;
	}

	.add_tit {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.bg {
		background: #F5F5F5;
	}

	.bgs {
		background: #F5F8FF;

	}

	.green {
		width: 16rpx;
		height: 16rpx;
		background: #1FC657;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.orgin {
		width: 16rpx;
		height: 16rpx;
		background: #FBAC04;
		border-radius: 50%;
		margin-right: 20rpx;
	}

	.btn {
		height: 78rpx;
		background: linear-gradient(87deg, #346EF6 0%, #7BA2FF 100%);
		border-radius: 4rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		margin: 30rpx 30rpx 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>